package toDo.pack;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Register extends Activity {
	static User[] user = ToDoActivity.getArray();
	
	Button registers;
	EditText ruser, rpass, rname, email; 
	TextView rerror;
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register);
        
        registers = (Button)findViewById(R.id.breg);
        ruser = (EditText) findViewById(R.id.trusername);
        rpass = (EditText) findViewById(R.id.trpassword);
        rname = (EditText) findViewById(R.id.tName);
        email = (EditText) findViewById(R.id.email);
        rerror = (TextView) findViewById(R.id.trerror);
        
       registers.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				String usertemp = ruser.getText().toString();
				String passtemp = rpass.getText().toString();
				String emailtemp = email.getText().toString();
				String nametemp = rname.getText().toString();
				
				if(usertemp.equals("") || passtemp.equals("") || emailtemp.equals("") || nametemp.equals(""))
					rerror.setText("You must fill out all fields");
				else{
					int count = 0;
					while(user[count] != null) count++;
					
					user[count] = new User(emailtemp,usertemp,passtemp,nametemp);
					ruser.setText("");
					rpass.setText("");
					email.setText("");
					rname.setText("");
					
					rerror.setText("Thank You!  Log in now");
				}
				
				Intent myIntent = new Intent(v.getContext(), ToDoActivity.class);
				v.getContext().startActivity(myIntent);
			}
		});
	}
	public static User[] getArray(){
    	return user;
    }
}
